<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="css/mui.min.css">
		<style>
			html,body {
				background-color: #efeff4;
			}
			.title{
				margin: 20px 15px 10px;
				color: #6d6d72;
				font-size: 15px;
			}
			#changeimg{
				width: 40px;
				height: 40px;
			}
		</style>
	</head>

	<body>
		<!--<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">设置</h1>
		</header>-->
		<div class="mui-content">
			<ul class="mui-table-view">
				<li class="mui-table-view-cell mui-media">
					<a class="mui-navigate-right" href="javascript:;">
						<img id="changeimg" class="mui-media-object mui-pull-left" src="images/qq.png">
						<div class="mui-media-body">
							<span id="name">用户名</span>
							<p id="repartment" class="mui-ellipsis">用户简介</p>
						</div>
					</a>
				</li>
			</ul>
			<ul class="mui-table-view" style="margin-top: 30px;">
				<li class="mui-table-view-cell">
					<a class="mui-navigate-right">
						新消息通知
					</a>
				</li>
				<li class="mui-table-view-cell">
					<a class="mui-navigate-right">
						隐私
					</a>
				</li>
				<li class="mui-table-view-cell">
					<a class="mui-navigate-right">
						通用
					</a>
				</li>
			</ul>
			<ul class="mui-table-view" style="margin-top: 25px;">
				<li class="mui-table-view-cell">
					<a id="about" class="mui-navigate-right">
						关于mui
					</a>
				</li>
			</ul>
			<ul class="mui-table-view" style="margin-top: 25px;">
				<li class="mui-table-view-cell">
					<a id="logout" style="text-align: center;color: #FF3B30;">
						退出登录
					</a>
				</li>
			</ul>
		</div>
		</style>
	</body>
	<script src="js/mui.min.js"></script>
	<script>
		mui.init({
			swipeBack:true //启用右滑关闭功能
		});
		document.getElementById("about").addEventListener('tap',function () {
			//获得主页面的webview
			var main = plus.webview.currentWebview().parent();
			//触发主页面的gohome事件
			mui.fire(main,'gohome');
		});
		
		mui.plusReady(function() {
			document.getElementById("logout").addEventListener("tap", function() {
			            var wvs=plus.webview.all();
			            var dqck=plus.webview.currentWebview();
			            var btnArray = ['取消', '确定'];
			            mui.confirm('确定注销当前用户?', 'chatapp', btnArray, function(e) {
					    if (e.index == 1) {
						plus.webview.close("main");
						plus.webview.close("index");
						localStorage.clear();
						plus.webview.open("login.html","login");
					}
					})
				});
				
			document.getElementById("changeimg").addEventListener("tap", function() {
				addpic();
			});
		});
		
		function addpic(){
				var btnArray = [{title:"拍照"},{title:"相册"}];
					plus.nativeUI.actionSheet( {
						title:"图片选择",
						cancel:"取消",
						buttons:btnArray
					}, function(e){
						var index = e.index;
						switch (index){
							case 0:
								break;
							case 1:
								shareCameraPicture();
								break;
							case 2:
								galleryImg();
								break;
						}
						
					} );
			}
		
		// 从相册中选择图片 
		function galleryImg() {
			// 从相册中选择图片
		    plus.gallery.pick( function(path){
		    	document.getElementById("changeimg").src=path;
		    	console.log(path);
		    }, function ( e ) {
		    	mui.toast( "取消选择图片" );
		    }, {filter:"image"} );
		}
		
		function shareCameraPicture(){
				var cmr=plus.camera.getCamera();
				cmr.captureImage(function(p){
					plus.io.resolveLocalFileSystemURL(p,function(entry){
						//picurl.src=entry.toLocalURL();
						//picurl.realUrl=p;
						//path = p;
						document.getElementById("changeimg").src=entry.toLocalURL();
					},function(e){
						mui.toast("读取拍照文件错误："+e.message);
					} );
				},function(e){
					mui.toast( "拍照失败："+e.message );
				});
			}
	</script>
</html>